package com.jf.ollama.controller;

import org.springframework.ai.chat.client.ChatClient;
import org.springframework.ai.ollama.OllamaChatModel;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import reactor.core.publisher.Flux;

/**
 * Created with IntelliJ IDEA
 * Description:
 * User:22954
 * Date:2025-06-14
 * Time:0:32
 */
@RestController
public class ChatController {
    private final ChatClient chatClient;
    public ChatController(OllamaChatModel ollamaChatModel) {
        this.chatClient = ChatClient.create(ollamaChatModel);
    }

    @GetMapping("/chat1")
    public String chat1(@RequestParam("message") String message) {
        return chatClient.prompt().user(message).call().content();
    }
    @GetMapping(value = "/chat2", produces = "text/html;charset=UTF-8")
    public Flux<String> chat2(@RequestParam("message") String message) {
        return chatClient.prompt().user(message).stream().content();
    }
}
